package com.etc.controller;

import com.etc.dto.Result;
import com.etc.entity.Department;
import com.etc.entity.Doctor;
import com.etc.service.DepartmentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/department")
public class DepartmentController {
    private static final Logger logger = LoggerFactory.getLogger(DepartmentController.class);

    @Autowired
    private DepartmentService departmentService;

    @GetMapping("/root")
    public @ResponseBody Result getRootdepartment(){
        List<Department> departmentList =departmentService.findAllDepartment();
        if(!departmentList.isEmpty()){
            return new Result().ok(departmentList);
        }
        return new Result().fail(0,"没有相关数据");
    }

    @GetMapping("/doctor")
    public @ResponseBody Result getDoctorBydeptId(Integer deptId){
        if(deptId !=null){
            List<Doctor> doctorList =departmentService.findAllDoctorByDeptId(deptId);
            if(!doctorList.isEmpty()){
                return new Result().ok(doctorList);
            }
        }
        return new Result().fail(0,"没有相关数据");
    }

}
